﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage2.master" AutoEventWireup="true" CodeFile="ManageContact.aspx.cs" Inherits="Default2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <div style="height: 600px">

    <br />

        <asp:Button ID="Button1" runat="server" Text="新建联系人" onclick="Button1_Click" 
            UseSubmitBehavior="False" />
        <asp:Panel ID="Panel1" runat="server" Visible="False">
            <table style="width:100%; height:100%;">
                <tr>
                    <td style="width: 45px" >
                        姓名:</td>
                    <td >
                        <asp:TextBox ID="TextBoxName" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td style="width: 45px">
                        性别:</td>
                    <td class="style6">
                        <asp:DropDownList ID="DropDownListSex" runat="server">
                            <asp:ListItem>男</asp:ListItem>
                            <asp:ListItem>女</asp:ListItem>
                            <asp:ListItem>保密</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td style="width: 45px">
                        出生日期:</td>
                    <td class="style6">
                        <asp:DropDownList ID="ddlYear" runat="server" 
                        CssClass="textbox">
                        </asp:DropDownList>
                        年 
                        <asp:DropDownList ID="ddlMonth" runat="server" 
                        CssClass="textbox">
                        </asp:DropDownList>
                        月 
                        <asp:DropDownList ID="ddlDay" runat="server" 
                        CssClass="textbox">
                        </asp:DropDownList>
                        日</td>
                </tr>
                <tr>
                    <td style="width: 45px">
                        头像:</td>
                    <td class="style6">
                        <asp:Image ID="Image2" runat="server" Height="51px" Width="70px" />
                        
                    

                        <br />

                        <asp:FileUpload ID="FileUpload1" runat="server" />


                    </td>
                </tr>
                <tr>
                    <td style="width: 45px">
                        地址:</td>
                    <td class="style6">
                        <asp:TextBox ID="TextBoxAddress" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td style="width: 45px">
                        电话:</td>
                    <td class="style6">
                        <asp:TextBox ID="TextBoxPhone" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td style="width: 45px">
                        邮箱:</td>
                    <td class="style6">
                        <asp:TextBox ID="TextBoxEmail" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td style="width: 45px; height: 31px;">
                        班级:</td>
                    <td class="style9" style="vertical-align: middle; height: 31px;">
                        <asp:DropDownList ID="DropDownListClass" runat="server" DataTextField="class" 
                            DataValueField="class" datasourceid="SqlDataSource2">
                        </asp:DropDownList>
                        
                        <asp:Button ID="Button5" runat="server" Text="新建班级" onclick="Button5_Click" 
                            UseSubmitBehavior="False" />
                        <asp:DropDownList ID="DropDownList1" runat="server" 
                            DataSourceID="XmlDataSource1" DataTextField="name" DataValueField="name" 
                            Visible="False">
                        </asp:DropDownList>
                        <asp:DropDownList ID="DropDownList2" runat="server" 
                            DataSourceID="XmlDataSource2" DataTextField="name" DataValueField="name" 
                            Visible="False">
                        </asp:DropDownList>
                        
                            <asp:TextBox ID="TextBoxClass" runat="server" 
                            Visible="False"></asp:TextBox>
                            <asp:Button ID="Button7" runat="server" onclick="Button7_Click" Text="取消" 
                            Visible="False" />
                  
                        <br />
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:Label ID="Label1" runat="server" style="color: #FF0000"></asp:Label>
                        <br />
                        <br />
                        &nbsp;<asp:Button ID="Button4" runat="server" onclick="Button4_Click" 
                            Text="确定" />
                        &nbsp;<input type="button" value="取消" onclick="javascript:history.go(-1);"  /></td>
                </tr>
            </table>
        </asp:Panel>
        <asp:ListView ID="ListView1" runat="server" DataKeyNames="id" 
        DataSourceID="SqlDataSource1" EnableModelValidation="True" 
        GroupItemCount="2">

        <EditItemTemplate>
            <td runat="server" style="background-color: #FFCC66;color: #000080;">
                姓名:
                <asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>' />
                <br />
                性别:
                <asp:TextBox ID="sexTextBox" runat="server" Text='<%# Bind("sex") %>' />
                <br />
                生日:
                <asp:TextBox ID="birthTextBox" runat="server" Text='<%# Bind("birth") %>' />
                <br />
                地址:
                <asp:TextBox ID="addressTextBox" runat="server" Text='<%# Bind("address") %>' />
                <br />
                电话:
                <asp:TextBox ID="phoneTextBox" runat="server" Text='<%# Bind("phone") %>' />
                <br />
                邮箱:
                <asp:TextBox ID="emailTextBox" runat="server" Text='<%# Bind("email") %>' />
                <br />
                <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="更新" />
                <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="取消" />

            </td>
        </EditItemTemplate>
        <EmptyDataTemplate>
            <table runat="server" 
                style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;">
                <tr>
                    <td>
                        未返回数据。</td>
                </tr>
            </table>
        </EmptyDataTemplate>
        <EmptyItemTemplate>
            <td runat="server" />
        </EmptyItemTemplate>
        <GroupTemplate>
            <tr ID="itemPlaceholderContainer" runat="server">
                <td ID="itemPlaceholder" runat="server">
                </td>
            </tr>
        </GroupTemplate>
        <InsertItemTemplate>
            <td runat="server" style="">
                user:
                <asp:TextBox ID="userTextBox" runat="server" Text='<%# Bind("user") %>' />
                <br />
                name:
                <asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>' />
                <br />
                sex:
                <asp:TextBox ID="sexTextBox" runat="server" Text='<%# Bind("sex") %>' />
                <br />
                birth:
                <asp:TextBox ID="birthTextBox" runat="server" Text='<%# Bind("birth") %>' />
                <br />
                address:
                <asp:TextBox ID="addressTextBox" runat="server" Text='<%# Bind("address") %>' />
                <br />
                phone:
                <asp:TextBox ID="phoneTextBox" runat="server" Text='<%# Bind("phone") %>' />
                <br />
                email:
                <asp:TextBox ID="emailTextBox" runat="server" Text='<%# Bind("email") %>' />
                <br />
                class:
                <asp:TextBox ID="classTextBox" runat="server" Text='<%# Bind("class") %>' />
                <br />
                image:
                <asp:TextBox ID="imageTextBox" runat="server" Text='<%# Bind("image") %>' />
                <br />
                <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="插入" />
                <br />
                <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="清除" />
                <br />
            </td>
        </InsertItemTemplate>
        <ItemTemplate>
                 <td runat="server" style=" width:50%">
                <table runat="server" style=" margin: 5px; background-color: #FFFBD6; color: #333333; width:97%; line-height: 16px;" >
                    <tr>
                        <td valign="top" width="128">

                            <OBJECT data="<%# Eval("image")%>" type="image/jpeg" style="width: 128px; height: 128px; margin: 5px">
                            <OBJECT data="images/noimage.gif" type="image/jpeg" style="width: 128px; height: 128px; margin: 5px">
                            </OBJECT>
                            </OBJECT>
                        </td>
                        <td>
                            <table>
                                <tr><td>姓名:<%# Eval("name") %></td></tr>
                                <tr><td>性别:<%# Eval("sex") %></td></tr>
                                <tr><td>生日:<%# Eval("birth") %></td></tr>
                                <tr><td>电话:<%# Eval("phone") %></td></tr>
                                <tr><td>邮件:<%# Eval("email") %></td></tr>
                                <tr><td style="word-break:break-all; vertical-align: top;">地址:<%# Eval("address") %></td></tr>
                                <tr>                                       
                                <td>
                                <asp:Button ID="Button3" runat="server" CommandName="Edit" Text="编辑" />
                                <asp:Button ID="Button2" OnClientClick="return confirm('确定要删除该联系人吗？')" runat="server" CommandName="Delete" Text="删除" />                                
                                <br />
                                </td>
                                </tr>
                            </table>
                        </td>                        
                    </tr>
                    
                </table>                
            </td>

   
        </ItemTemplate>
        <AlternatingItemTemplate>
            <td runat="server" style="width: 50%; " >
                <table id="Table1" runat="server" style="margin: 5px;background-color: #FAFAD2;color: #284775;width:97%;line-height: 16px;">
                    <tr>
                        <td valign="top" width="128">
                                             <OBJECT data="<%# Eval("image")%>" type="image/jpeg" style="width: 128px; height: 128px; margin: 5px">
                            <OBJECT data="images/noimage.gif" type="image/jpeg" style="width: 128px; height: 128px; margin: 5px">
                            </OBJECT>
                            </OBJECT> </td>
                        <td>
                            <table>
                                <tr><td>姓名:<%# Eval("name") %></td></tr>
                                <tr><td>性别:<%# Eval("sex") %></td></tr>
                                <tr><td>生日:<%# Eval("birth") %></td></tr>
                                <tr><td>电话:<%# Eval("phone") %></td></tr>
                                <tr><td>邮件:<%# Eval("email") %></td></tr>
                                <tr><td style="word-break:break-all; vertical-align: top;">地址:<%# Eval("address") %></td></tr>
                            
                            </table>

                            <table>

                                <tr>                                       
                                <td>
                                <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="编辑" />
                                <asp:Button ID="DeleteButton" runat="server" OnClientClick="return confirm('确定要删除该联系人吗？')" CommandName="Delete" Text="删除" />
                                </td>
                                </tr>
                            </table>
                        </td>                        
                    </tr>
                    
                </table>                
            </td>
        </AlternatingItemTemplate>

        <LayoutTemplate>
            <div style="height: 520px;">
            <table runat="server" style="width: 100%;">
                <tr runat="server">
                    <td runat="server" >
                        <table ID="groupPlaceholderContainer" runat="server" border="0" 
                            style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif; width: 100%;">
                            <tr ID="groupPlaceholder" runat="server">
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr runat="server">

                </tr>
            </table>
            </div>

            <div  runat="server" 
                style="text-align: center;background-color: #FFCC66;font-family: Verdana, Arial, Helvetica, sans-serif;color: #333333;">
                <asp:DataPager ID="DataPager1" runat="server" PageSize="6">
                    <Fields>
                        <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                            ShowLastPageButton="True" />
                    </Fields>
                </asp:DataPager>
            </div>

        </LayoutTemplate>
        <SelectedItemTemplate>
            <td runat="server" 
                style="background-color: #FFCC66;font-weight: bold;color: #000080;">
                id:
                <asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>' />
                <br />
                user:
                <asp:Label ID="userLabel" runat="server" Text='<%# Eval("user") %>' />
                <br />
                name:
                <asp:Label ID="nameLabel" runat="server" Text='<%# Eval("name") %>' />
                <br />
                sex:
                <asp:Label ID="sexLabel" runat="server" Text='<%# Eval("sex") %>' />
                <br />
                birth:
                <asp:Label ID="birthLabel" runat="server" Text='<%# Eval("birth") %>' />
                <br />
                address:
                <asp:Label ID="addressLabel" runat="server" Text='<%# Eval("address") %>' />
                <br />
                phone:
                <asp:Label ID="phoneLabel" runat="server" Text='<%# Eval("phone") %>' />
                <br />
                email:
                <asp:Label ID="emailLabel" runat="server" Text='<%# Eval("email") %>' />
                <br />
                class:
                <asp:Label ID="classLabel" runat="server" Text='<%# Eval("class") %>' />
                <br />
                image:
                <asp:Label ID="imageLabel" runat="server" Text='<%# Eval("image") %>' />
                <br />
                <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="删除" />
                <br />
                <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="编辑" />
                <br />
            </td>
        </SelectedItemTemplate>
    </asp:ListView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
        DeleteCommand="DELETE FROM [member] WHERE [id] = @original_id" 
        InsertCommand="INSERT INTO [member] ([user], [name], [sex], [birth], [address], [phone], [email], [class], [image]) VALUES (@user, @name, @sex, @birth, @address, @phone, @email, @class, @image)" 
        OldValuesParameterFormatString="original_{0}" 
        SelectCommand="SELECT * FROM [member] where class!=''" 
        UpdateCommand="UPDATE [member] SET [name] = @name, [sex] = @sex, [birth] = @birth, [address] = @address, [phone] = @phone, [email] = @email WHERE [id] = @original_id ">
        <DeleteParameters>
            <asp:Parameter Name="original_id" Type="Int32" />
            <asp:Parameter Name="original_user" Type="String" />
            <asp:Parameter Name="original_name" Type="String" />
            <asp:Parameter Name="original_sex" Type="String" />
            <asp:Parameter DbType="Date" Name="original_birth" />
            <asp:Parameter Name="original_address" Type="String" />
            <asp:Parameter Name="original_phone" Type="String" />
            <asp:Parameter Name="original_email" Type="String" />
            <asp:Parameter Name="original_class" Type="String" />
            <asp:Parameter Name="original_image" Type="String" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="user" Type="String" />
            <asp:Parameter Name="name" Type="String" />
            <asp:Parameter Name="sex" Type="String" />
            <asp:Parameter DbType="Date" Name="birth" />
            <asp:Parameter Name="address" Type="String" />
            <asp:Parameter Name="phone" Type="String" />
            <asp:Parameter Name="email" Type="String" />
            <asp:Parameter Name="class" Type="String" />
            <asp:Parameter Name="image" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="user" Type="String" />
            <asp:Parameter Name="name" Type="String" />
            <asp:Parameter Name="sex" Type="String" />
            <asp:Parameter DbType="Date" Name="birth" />
            <asp:Parameter Name="address" Type="String" />
            <asp:Parameter Name="phone" Type="String" />
            <asp:Parameter Name="email" Type="String" />
            <asp:Parameter Name="class" Type="String" />
            <asp:Parameter Name="image" Type="String" />
            <asp:Parameter Name="original_id" Type="Int32" />
            <asp:Parameter Name="original_user" Type="String" />
            <asp:Parameter Name="original_name" Type="String" />
            <asp:Parameter Name="original_sex" Type="String" />
            <asp:Parameter DbType="Date" Name="original_birth" />
            <asp:Parameter Name="original_address" Type="String" />
            <asp:Parameter Name="original_phone" Type="String" />
            <asp:Parameter Name="original_email" Type="String" />
            <asp:Parameter Name="original_class" Type="String" />
            <asp:Parameter Name="original_image" Type="String" />
        </UpdateParameters>
    </asp:SqlDataSource>

                        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
                        SelectCommand="SELECT DISTINCT [class] FROM [class]"></asp:SqlDataSource>
                        <asp:XmlDataSource ID="XmlDataSource1" runat="server" 
        DataFile="~/XMLFile.xml" XPath="school/department"></asp:XmlDataSource>
    <asp:XmlDataSource ID="XmlDataSource2" runat="server" DataFile="~/XMLFile.xml" 
        XPath="school/grade"></asp:XmlDataSource>

        </div>
</asp:Content>

